<?php /*a:2:{s:73:"D:\leruge_program\local\admin\application\admin\view\admin\role_list.html";i:1592208792;s:71:"D:\leruge_program\local\admin\application\admin\view\common\__base.html";i:1592181449;}*/ ?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/static/admin/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <link rel="stylesheet" href="/static/admin/css/public.css" media="all">
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style id="layuimini-bg-color">
    </style>
    
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        
<table id="table" lay-filter="table"></table>

<!--操作-->
<script id="operation" type="text/html">
    <button class="layui-btn layui-btn-xs" lay-event="edit">编辑</button>
    <button class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</button>
</script>

<!--工具栏-->
<script id="toolbar" type="text/html">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
        <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="del">删除</button>
        <button class="layui-btn layui-btn-sm" lay-event="refresh">刷新</button>
    </div>
</script>

    </div>
</div>

<script src="/static/admin/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="/static/admin/js/lay-config.js?v=2.0.0" charset="utf-8"></script>

<script>
    layui.use(["table", 'miniTab'], function () {
        let table = layui.table,
            miniTab = layui.miniTab,
            $ = layui.jquery;

        // 数据表格
        let dataTable = table.render({
            elem: "#table",
            id: "table",
            cols: [[
                {type: "checkbox"},
                {title: "角色名", field: "title"},
                {title: "添加时间", field: "create_time"},
                {title: "操作", toolbar: "#operation"}
            ]],
            url: "<?php echo url('admin/admin/roleList'); ?>",
            method: "post",
            parseData: function (res) {
                return {
                    code: res.code,
                    msg: res.msg,
                    data: res.data.list,
                    count: res.data.count
                };
            },
            page: false,
            toolbar: "#toolbar",
            defaultToolbar: []
        });

        // 工具栏
        table.on("toolbar(table)", function (obj) {
            if (obj.event == "add") {
                miniTab.openNewTabByIframe({
                    title: "添加角色",
                    href: "<?php echo url('admin/admin/addRole'); ?>"
                });
            } else if (obj.event == "refresh") {
                location.reload();
            } else if (obj.event == "del") {
                layer.confirm("确定删除吗？", {icon: 3, title: "删除角色"}, function () {
                    let checkStatus = table.checkStatus('table');
                    if (checkStatus.data.length == 0) {
                        layer.msg("至少选择一个");
                    } else {
                        let role_ids = checkStatus.data.map(x => {return x.id}).join(",");
                        $.post("<?php echo url('admin/admin/delRoles'); ?>", {role_ids: role_ids}, function (res) {
                            if (res.code == 1) {
                                layer.msg(res.msg, function () {
                                    location.reload();
                                });
                            } else {
                                layer.msg(res.msg);
                            }
                        }, "json");
                    }
                });
            }
        });

        // 工具
        table.on("tool(table)", function (obj) {
            if (obj.event == "edit") {
                miniTab.openNewTabByIframe({
                    title: "编辑角色",
                    href: "<?php echo url('admin/admin/editRole'); ?>?id=" + obj.data.id
                });
            } else if (obj.event == "del") {
                layer.confirm("确定删除吗？", {icon: 3, title: "删除角色"}, function () {
                    $.post("<?php echo url('admin/admin/delRoles'); ?>", {role_ids: obj.data.id}, function (res) {
                        layer.msg(res.msg);
                        if (res.code == 1) {
                            obj.del();
                        }
                    }, "json");
                });
            }
        });
    });
</script>

</body>
</html>
